package com.sun.blog.sunblog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sun.blog.sunblog.base.BaseService;
import com.sun.blog.sunblog.mapper.BlogMapper;
import com.sun.blog.sunblog.model.Blog;
import com.sun.blog.sunblog.service.BlogService;
import com.sun.org.apache.regexp.internal.recompile;

@Service("blogService")
public class BlogServiceImpl extends BaseService implements BlogService{
	@Autowired
	private BlogMapper blogMapper;
	
	public Blog findBlogById(Long id){
		try {
			return blogMapper.findBlogById(id);
		} catch (Exception e) {
			log.error("根据Id查询Blog出错", e);
			return null;
		}
	}

	public List<Blog> findAllBlogs(){
		try {
			return blogMapper.findAllBlogs();
		} catch (Exception e) {
			log.error("查询全部Blog出错", e);
			return null;
		}
	}

	public List<Blog> findBlogByCategoryId(Long id){
		try {
			return blogMapper.findBlogByCategoryId(id);
		} catch (Exception e) {
			log.error("根据分类查询Blog出错", e);
			return null;
		}
	}
	
	public Blog findPreBlog(Long id){
		try {
			return blogMapper.findPreBlog(id);
		} catch (Exception e) {
			log.error("查询前一篇Blog失败", e);
			return null;
		}
	}
	
	public Blog findNextBlog(Long id){
		try {
			return blogMapper.findNextBlog(id);
		} catch (Exception e) {
			log.error("查询后一篇Blog失败", e);
			return null;
		}
	}

	public Integer addBlog(Blog blog){
		try {
			return blogMapper.addBlog(blog);
		} catch (Exception e) {
			log.error("添加Blog出错", e);
			return -1;
		}
	}

	public Integer updateBlog(Blog blog){
		try {
			return blogMapper.updateBlog(blog);
		} catch (Exception e) {
			log.error("更新Blog出错", e);
			return -1;
		}
	}
}
